import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.SwingConstants;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class GUI_connexion extends JDialog {


	/**
	 * 
	 */
	private static final long serialVersionUID = -7479658303777015357L;
	private final JPanel contentPanel = new JPanel();
	private JTextField textField_1;
	private JPasswordField passwordField;
	private GUI_Client Parent;
	private JDialog moi;

	/**
	 * Create the dialog.
	 */
	public GUI_connexion(GUI_Client parent) {
		moi=this;
		Parent=parent;
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setTitle("Connexion");
		setBounds(100, 100, 282, 140);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		{
			JLabel lblUtilisateur = new JLabel("Utilisateur : ");
			lblUtilisateur.setHorizontalAlignment(SwingConstants.RIGHT);
			lblUtilisateur.setBounds(10, 11, 95, 14);
			contentPanel.add(lblUtilisateur);
		}
		
		JLabel lblMotDePasse = new JLabel("Mot de passe : ");
		lblMotDePasse.setHorizontalAlignment(SwingConstants.RIGHT);
		lblMotDePasse.setBounds(10, 36, 95, 14);
		contentPanel.add(lblMotDePasse);
		
		textField_1 = new JTextField();
		textField_1.setColumns(10);
		textField_1.setBounds(109, 8, 150, 20);
		contentPanel.add(textField_1);
		
		passwordField = new JPasswordField();
		passwordField.setBounds(109, 33, 150, 20);
		contentPanel.add(passwordField);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						String user = textField_1.getText().trim();
						String mdp = passwordField.getText().trim();
						
						if (user.equals("") || mdp.equals("")){
							JOptionPane.showConfirmDialog(null, "Veuillez saisir un utilisateur et un mot de passe","Erreur",JOptionPane.OK_OPTION,JOptionPane.ERROR_MESSAGE);
						}else{
							Parent.setUserMdp(user, mdp);
							moi.dispose();
						}
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						moi.dispose();
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}
}
